package com.liziing.config;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class WebInfoHandlerInterceptor implements HandlerInterceptor {

    private StringRedisTemplate stringRedisTemplate;

    public WebInfoHandlerInterceptor(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;
    }
    //拦截获取网站信息
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        System.out.println(requestURI);
        //从缓存中获取登录信息
        String token = stringRedisTemplate.opsForValue().get("token");
        if (token == null){
            return false;
        } else {  //如果没有获取到，说明网站正在维护中   就提示维护中，然后不放行
            //如果找到了网站信息，就放行
            return true;
        }

    }
}
